import 'dart:io';

void main() {
  test();
}

test() async {
  try {
    String token = await LoginViewModel().login();
    await LoginViewModel().setToken(token);
    // ignore: unnecessary_null_comparison
    if (token != null) {
      print("登录成功");
    } else {
      print("登录失败");
    }
  } catch (e) {
    print(e);
  }
}

//登录
class LoginViewModel {
  Future<String> login() async {
    print("登录中...");
    await Future.delayed(Duration(seconds: 2));
    return '123token1234';
  }

  // 设置token
  Future<bool> setToken(String token) {
    return Future<bool>(() {
      print('正在设置token...');
      sleep(Duration(seconds: 2));
      print('$token保存成功');
      return true;
    });
  }
}
